<?php

class Search_Form_Search extends Zend_Form
{
    public $text;
    
    public function __construct($text=null)
    {
        $this->text=$text;
        
        parent::__construct();
    }
    
    public function init()
    {
        $this->setMethod('POST');
        $this->setAction(Zend_Registry::get('view')->fixUrl('search'));
        
        $text=new Zend_Form_Element_Text('query');
        $text->setLabel('Search')
              ->addFilter('StringTrim')
              ->addFilter('StripTags')
              ->addValidator(
                    'StringLength',
                    true,
                    array(
                        'min' => 3,
                        'max' => 255
                    )
              )
              ->addDecorator(new Search_Form_SearchDecorator())
              ->setValue($this->text)
              ->setRequired(true);

         $submit=new Zend_Form_Element_Submit('submit');
         $submit->setValue('Search')
                ->setLabel('')
                ->addDecorator(new Search_Form_SearchDecorator());
               
         $csrf=new Zend_Form_Element_Hash('csrf',array('salt' => 'search'));
         $csrf->setOptions(array(
                            'ignore' => true,
                        ))
              ->addDecorator(new Search_Form_SearchDecorator());
              
        $this->addElements(
            array(
                $text,
                $submit,
                $csrf
                )
        );
    }
}

